package com.example.Controller;

import com.atguigu.model.system.SysMenu;
import com.atguigu.vo.system.AssginMenuVo;
import com.example.Result;
import com.example.ResultCodeEnum;
import com.example.Service.SysMenuService;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

@Tag(name = "菜单管理")
@RequestMapping("/admin/system/sysMenu")
@RestController
public class SysMenuController {
    @Resource
    private SysMenuService sysMenuService;

    @ApiOperation("菜单列表")
    @GetMapping("/findNodes")
    public Result findNode() {
        List<SysMenu> list = sysMenuService.getlist();
        return Result.build(list, ResultCodeEnum.SUCCESS);

    }

    @ApiOperation("新增")
    @PostMapping("/save")
    public Result add(@RequestBody SysMenu sysMenu) {
        sysMenuService.save(sysMenu);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @ApiOperation("修改")
    @PutMapping("/update")
    public Result update(@RequestBody SysMenu sysMenu) {
        sysMenuService.updateById(sysMenu);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @ApiOperation("删除")
    @DeleteMapping("/remove/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        sysMenuService.delete(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @ApiOperation("角色所属菜单")
    @GetMapping("/toAssign/{roleId}")
    public Result assign(@PathVariable("roleId") Integer roleId) {
        List<SysMenu> list = sysMenuService.getlistByRoleId(roleId);
        return Result.build(list, ResultCodeEnum.SUCCESS);

    }
    @ApiOperation("分配菜单")
    @PostMapping("/doAssign")
    public Result doassign(@RequestBody AssginMenuVo assiginMenuVo){
        sysMenuService.doassign(assiginMenuVo);
        return Result.build(null,ResultCodeEnum.SUCCESS);

    }

}
